package com.jackstraw.dbtool.controller;

import com.jackstraw.dbtool.common.Result;
import com.jackstraw.dbtool.exception.MyException;
import com.jackstraw.dbtool.pojo.CreateDBTxtData;
import com.jackstraw.dbtool.service.ICreateDBTxtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 版权所有： 稻草人
 * 创建者： wenhe
 * 创建时间: 2020-01-16
 * 描述：
 * 其它：
 **/
@RestController
@RequestMapping(value="/createDBTxt")
public class CreateDBTxtController {

    @Autowired
    private ICreateDBTxtService createDBTxtService;

    /**
     * 生成数据库表数据到指定的文件中
     * @param createDBTxtData
     * @return
     */
    @RequestMapping(value="/createDBTxt")
    public Result<Object> createDBTxt(CreateDBTxtData createDBTxtData) {
        Result<Object> result = new Result<>();
        try {
            createDBTxtService.createDBTxt(createDBTxtData);
            result.success();
        } catch (MyException e) {
            result.error(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            result.error("数据异常，请联系管理员！");
        }
        return result;
    }
}
